import uniCrazyRouter from "uni-crazy-router";

var routes = ROUTES_MAP


export function setupRouter (app) {
	
    // 接收vue3的实例，并注册uni-crazy-router
    app.use(uniCrazyRouter)
	
}

uniCrazyRouter.beforeEach(async (to, from ,next)=>{
	
	let url = to.url
    // 逻辑代码
	if(checkLogin(url)){
		next()	
	}

})



uniCrazyRouter.afterEach((to, from)=>{
 
	
})

uniCrazyRouter.onError((to, from)=>{
    // 逻辑代码 
	 
	
	   
})

export function  checkLogin(url){

	let route = routes["/" + url]

	if(route && route?.meta?.auth == true && uni.$store.userStore.isLogin == false){
	
		return false
	}
	return true
	
}

